﻿
namespace Foggy.Data.Extensions
{
    using System;
    using System.Collections.Generic;

    public static class TimeSpanExtensions
    {
        public static string ToDisplayString(this TimeSpan timeSpan)
        {
            var elements = new List<string>();

            if (timeSpan.Days > 0)
            {
                elements.Add(string.Format("{0} {1}", timeSpan.Days, timeSpan.Days == 1 ? "day" : "days"));
            }

            if (timeSpan.Hours > 0)
            {
                elements.Add(string.Format("{0} {1}", timeSpan.Hours, timeSpan.Hours == 1 ? "hour" : "hours"));
            }

            if (timeSpan.Minutes > 0)
            {
                elements.Add(string.Format("{0} {1}", timeSpan.Minutes, timeSpan.Minutes == 1 ? "minute" : "minutes"));
            }

            var message = string.Join(", ", elements);
            return message;
        }
    }
}
